package com.wdress.actions;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.DynaActionForm;
import org.hibernate.Query;
import org.hibernate.classic.Session;

import com.wdress.base.BaseAction;
import com.wdress.model.Wdress;
import com.wdress.model.Wkeyword;

public class HomeAction extends BaseAction{

	@Override
	public String executeAction(DynaActionForm form, Session session,
			HttpServletRequest arg2, HttpServletResponse arg3,String lang) throws Exception {
		Query query = session.createQuery("from Wkeyword where typeid <5 and types='categorie' and lang=?");
		query.setString(0, lang);
		List<Wkeyword> topCates= query.list();
		for(int i=0;i<topCates.size();i++){
			query = session.createQuery("from Wdress where dress_type =? and lang=?");
			query.setString(0, topCates.get(i).getKeyword());
			query.setString(1, lang);
			List<Wdress> cwdList = query.setMaxResults(3).list();
			topCates.get(i).setWdressList(cwdList);
		}
		arg2.setAttribute("topCates", topCates);
		query = session.createQuery("from Wdress where lang=?");
		query.setString(0, lang);
		List<Wkeyword> dresslist= query.setMaxResults(4).list();
		arg2.setAttribute("dresslist", dresslist) ;
		return "success";
	}
	
}
